package edu.univercidade.tcc.server.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import edu.univercidade.tcc.server.model.Priority;

public class PriorityServiceImpl implements PriorityService {

	private Comparator<Priority> priorityOrder = new Comparator<Priority>() {

		@Override
		public int compare(Priority arg0, Priority arg1) {
			return arg0.getPriorityPosition().compareTo(
					arg1.getPriorityPosition());
		}
	};

	public List<Priority> findAllPrioritys() {
		List<Priority> result = priorityDAO.findAll();
		Collections.sort(result, priorityOrder);
		return result;
	}

	public List<Priority> findPriorityEntries(int firstResult, int maxResults) {
		List<Priority> result = new ArrayList<Priority>(priorityDAO.findAll(
				new org.springframework.data.domain.PageRequest(firstResult
						/ maxResults, maxResults)).getContent());
		Collections.sort(result, priorityOrder);
		return result;
	}
}
